package fun.coding.linkedlist;


public class SimpleLinkedList {
	Node head = null;
	
	public Node getHead() {
		return head;
	}
	
	public void insert(int value) {
		Node n = new Node();
		n.setValue(value);
		
		if(head == null) {
			head = n;
			return;
		}
		
		Node iter = head;
		
		while(iter.getNext() != null) {
			iter = iter.getNext();
		}
		
		iter.setNext(n);
				
	}
	
	public void print() {
		Node n = head;
		while(n != null) {
			System.out.print(n.getValue() + " ");
			n = n.getNext();
		}
		System.out.println();
	}
	
	
	public void delete(int value) {
		if(isEmpty())
			return;
		
		Node n = head;
			
		while(n.getNext() != null) {
			if(n.getNext().getValue() == value) {
				n.setNext(n.getNext().getNext());
			}
			n = n.getNext();
		}
	}
	
	private boolean isEmpty() {
		return head == null ? true : false;
	}
	
}
